#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <arpa/inet.h>
#include <dlfcn.h>

#define PROXY         "127.0.0.1"
#define PROXY_PORT    9050
#define USERNAME      "toraliz"// "toraliz\0"
#define reqsize       sizeof(struct proxy_request)
#define ressize       sizeof(struct proxy_response)

/*
system call or util function we need to use:
- socket()
- connect()
- close()
- htons()
- inet_addr()
*/

//--------------------------------------------------------
// sock4 rfc: https://www.openssh.com/txt/socks4.protocol
//--------------------------------------------------------

typedef unsigned char int8;
typedef unsigned short int int16;
typedef unsigned int int32;

struct proxy_request {
    int8 vn;
    int8 cd;
    int16 dstport;
    int32 dstip;
    unsigned char userid[8];
};

typedef struct proxy_request Req;

struct proxy_response {
    int8 vn;
    int8 cd;
    int16 _;// ignored
    int32 __;// ignored
};

typedef struct proxy_response Res;

Req *request(const struct sockaddr_in *);

int connect(int, const struct sockaddr *, socklen_t);